// pages/index/havelist/havelist.js
let openSocket = require('../../../wss.js');
Page({


  /**
   * 页面的初始数据
   */
  data: {
    navbar: ['已点歌曲', '已唱歌曲'],
    currentTab: 0
  },
  navbarTap: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    // openSocket.init('04:BC:87:01:24:D3', '7f0000010902002b4d3320190121095123', 'ogEMlxBcC3g5mS-s4EGD0EEMESnc');
    // openSocket.connect("wss://wx.app.magimore.com/wss");

    // console.log(openSocket.event.wsstatus);
  },

  onShow: function () {
    this.getListData();

    // this.wsRegister();
  },


  getListData:function(){
    let that = this;
    openSocket.event.showsonglist = function (data) {
        console.log(data);
      wx.request({
        url: 'https://wx.api.magimore.com/api/song/getinfo', // 仅为示例，并非真实的接口地址
        data: {
          songid: data
        },
        method: "POST",
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {

          var array = [];

          var arr1 = JSON.parse(res.data);

          for (let i = 0; i < arr1.data.length; i++) {

            if (arr1.data.length == data.length && arr1.data[i]) {
              arr1.data[i].ID = data[i].ID;
              arr1.data[i].isrecorded = data[i].isrecorded;
              arr1.data[i].rec_id = data[i].rec_id;

              array.push(arr1.data[i]);
            }

          }
          that.setData({ songList: array });
          console.log(array);
        }
      })
    }

    openSocket.event.showsunglist = function (data) {
      wx.request({
        url: 'https://wx.api.magimore.com/api/song/getinfo', // 仅为示例，并非真实的接口地址
        data: {
          songid: data
        },
        method: "POST",
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {

          var array = [];

          var arr1 = JSON.parse(res.data);

          for (let i = 0; i < arr1.data.length; i++) {

            if (arr1.data.length == data.length && arr1.data[i]) {
              arr1.data[i].ID = data[i].ID;
              arr1.data[i].isrecorded = data[i].isrecorded;
              arr1.data[i].rec_id = data[i].rec_id;

              array.push(arr1.data[i]);
            }

          }
          that.setData({ sungList: array });
          console.log(array);
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },



  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },



  getType(type){
    var typeName = "";
      switch(type){
        case 0 :
          //
          break;
      }

      return typeName;
  },

  clickSong:function(e){
    openSocket.songselect(e.currentTarget.dataset.songid,0);
  },
  TopSong:function(e){
    console.log(2);
    openSocket.songupper(e.currentTarget.dataset.songid, e.currentTarget.dataset.ID);
  }
})